package xiao_jin.fantastic_journey.client.Item;

import net.minecraft.client.item.ModelPredicateProviderRegistry;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.ChargedProjectilesComponent;
import net.minecraft.item.Items;
import net.minecraft.util.Identifier;
import xiao_jin.fantastic_journey.core.common.item.EndBreathing;
import xiao_jin.fantastic_journey.core.init.ModItems;

public class ModModelPredicateProviderRegistry extends ModelPredicateProviderRegistry {
    public static void registerCustomModelData() {
        register(ModItems.RESONANCE, Identifier.ofVanilla("pull"), (stack, world, entity, seed) -> {
            if (entity == null) {
                return 0.0F;
            } else {
                return entity.getActiveItem() != stack ? 0.0F : (float) (stack.getMaxUseTime(entity) - entity.getItemUseTimeLeft()) / 20.0F;
            }
        });
        register(
                ModItems.RESONANCE,
                Identifier.ofVanilla("pulling"),
                (stack, world, entity, seed) -> entity != null && entity.isUsingItem() && entity.getActiveItem() == stack ? 1.0F : 0.0F
        );
        register(
                ModItems.END_BREATHING,
                Identifier.ofVanilla("pull"),
                (stack, world, entity, seed) -> {
                    if (entity == null) {
                        return 0.0F;
                    } else {
                        return EndBreathing.isCharged(stack)
                                ? 0.0F
                                : (float) (stack.getMaxUseTime(entity) - entity.getItemUseTimeLeft()) / (float) EndBreathing.getPullTime(stack, entity);
                    }
                }
        );
        register(
                ModItems.END_BREATHING,
                Identifier.ofVanilla("pulling"),
                (stack, world, entity, seed) -> entity != null && entity.isUsingItem() && entity.getActiveItem() == stack && !EndBreathing.isCharged(stack) ? 1.0F : 0.0F
        );
        register(ModItems.END_BREATHING, Identifier.ofVanilla("charged"), (stack, world, entity, seed) -> EndBreathing.isCharged(stack) ? 1.0F : 0.0F);
        register(ModItems.END_BREATHING, Identifier.ofVanilla("firework"), (stack, world, entity, seed) -> {
            ChargedProjectilesComponent chargedProjectilesComponent = stack.get(DataComponentTypes.CHARGED_PROJECTILES);
            return chargedProjectilesComponent != null && chargedProjectilesComponent.contains(Items.FIREWORK_ROCKET) ? 1.0F : 0.0F;
        });
    }
}
